from pydantic import BaseModel, Field

#对待判断产品进行类型和数据
class ProductModel(BaseModel):
    pd_id: str = Field(..., description="product id")
    pd_title: str = Field(..., description="product title")
    pd_desc: str = Field(..., description="product description")

    def __str__(self):
        return (
            f"pd_id: {self.pd_id}\n"
            f"pd_title: {self.pd_title}\n"
            f"pd_desc: {self.pd_desc[:100]}...(omitted)\n"
        )

    @property
    def ori_text(self):
        return f"pd_title: {self.pd_title}\npd_desc: {self.pd_desc}"


class ProductRemovePromotionalContentModel(BaseModel):
    pd_title: str = Field(
        ..., description="Product title after removing promotional content"
    )
    pd_desc: str = Field(
        ..., description="Product description after removing promotional content"
    )

    def __str__(self):
        return (
            f"pd_title: {self.pd_title}\n"
            f"pd_desc: {self.pd_desc[:100]}...(omitted)\n"
        )

    @property
    def rag_text(self):
        return f"pd_title: {self.pd_title}\npd_desc: {self.pd_desc}"


class SourceModel(BaseModel):
    """
    source
    """

"""在自动化系统中实现更细致和可解释的产品合规性评估。这是一个回答模型（整个流程的回答模型）"""
class ProbabilityResultModel(BaseModel):
    """
    ResultModel represents the outcome of a product evaluation process.
    """

    is_prohibited_probability: float = Field(
        ..., description="Probability of being prohibited, between 0 and 1"
    )
    requires_compliance_check_probability: float = Field(
        ..., description="Probability of requiring compliance check, between 0 and 1"
    )
    is_prohibited_reason: str = Field(
        ..., description="Reason for potential prohibition"
    )
    requires_compliance_check_reason: str = Field(
        ..., description="Reason for potential compliance check requirement"
    )

    def model_dump(self):
        is_prohibited = 0
        requires_compliance_check = 0
        if self.is_prohibited_probability > 0.2:
            #如果概率大于0.2，则认为该产品是禁止的，并且合规性标签直接列为0
            is_prohibited = 1
            requires_compliance_check = 0
        elif self.requires_compliance_check_probability > 0.5:
            #如果概率大于0.5，则认为该产品需要合规性检查，并且禁止标签直接列为0
            is_prohibited = 0
            requires_compliance_check = 1
            #返回的时候需要返回标签值和判断原因
        return {
            "is_prohibited": is_prohibited,
            "requires_compliance_check": requires_compliance_check,
            "source": {
                "is_prohibited_reason": self.is_prohibited_reason,
                "requires_compliance_check_reason": self.requires_compliance_check_reason,
            },
        }
